# barco/binrepos.py

import sys
import optparse
import barco.error
import barco.binrepos

## main() ##
def main():
    client = barco.binrepos.Client()
    
    usage = list()
    usage.append('usage: binrepos [options] <command> [args]')
    usage.append('')
    usage.append('Valid binrepos commands are:')
    usage.append('')
    usage.append('  list_tags           List all tags in the binary repository')
    usage.append('  create_tag <name>   Creates a new tag in the binary repository')

    parser = optparse.OptionParser(usage='\n'.join(usage), version='0.1')
    (option, args) = parser.parse_args()

    # list_modules is our default command
    if len(args) == 0: args = [ 'list_modules' ]

    # make sure our commands are lowercase
    command = args[0].lower()

    try:

        if command == 'create_tag': client.create_tag(*args[1:])
        elif command == 'list_tags' : client.list_tags(*args[1:])
        else: parser.error('invalid command specified: [%s]' % args[0])

    except barco.error.Error as e: parser.error(str(e))
    return 0

# execute main() if we are being run as standalone script.
if __name__ == '__main__': sys.exit(main())
